package com.liuwei.netty.reconnect;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class NettyReconnectClientHandler extends SimpleChannelInboundHandler<String> {
    private NettyClient nettyClient;;

    public NettyReconnectClientHandler(NettyClient nettyClient) {
        this.nettyClient = nettyClient;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, String msg) throws Exception {
        log.info("收到服务端的数据:" + msg);
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        log.info("服务器断线,尝试重新重连中....");
        nettyClient.connect();
    }
}
